package PlaneGame.CODE;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import static PlaneGame.CODE.GameFrame.*;
public class EnemyC extends Enemy{
    WinString winString=new WinString("",160,300);
    BossBloodString bossBloodString;
    int shotRate =20;//速率越小越快
    int shotR=0;

    public EnemyC() {
        super();
        this.speed=0;
        this.width=60;
        this.height=60;
        this.x=frameWidth/2-width/2;
        this.y=100;
        bossBloodString=new BossBloodString("",this.x,this.y-30);
        new Thread(bossBloodString).start();
        this.imageNumber=3;
        this.explodeImageNumber=6;
        this.paths= new String[]{"src/PlaneGame/IMAGE/enemy3_n1.png",
                "src/PlaneGame/IMAGE/enemy3_n2.png",
                "src/PlaneGame/IMAGE/enemy3_hit.png",
                "src/PlaneGame/IMAGE/enemy3_down1.png",
                "src/PlaneGame/IMAGE/enemy3_down2.png",
                "src/PlaneGame/IMAGE/enemy3_down3.png",
                "src/PlaneGame/IMAGE/enemy3_down4.png",
                "src/PlaneGame/IMAGE/enemy3_down5.png",
                "src/PlaneGame/IMAGE/enemy3_down6.png"};
        images=new BufferedImage[imageNumber+explodeImageNumber];
        for (int i = 0; i < images.length; i++) {
            try {
                images[i] = ImageIO.read(new File(paths[i]));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    @Override
    void init() {
        super.init();
        blood=100;
    }
    @Override
    void shift() {
        super.shift();
        bossBloodString.shift();
    }

    @Override
    void on() {
        super.on();
        bossBloodString.on();
    }

    @Override
    void off() {
        super.off();
        if (bossBloodString!=null) {
            bossBloodString.off();
        }
    }

    @Override
    void change() {
        super.change();
        shot();
    }
    void shot(){
        delete();
        shotR++;
        if(shotR>shotRate){
            create();
            shotR=0;
        }
    }
    void create(){
        tVector.add(new EnemyBullet((this.x),(this.y+this.height)));
        tVector.lastElement().moveType=1;
        tVector.lastElement().shift();
        new Thread(tVector.lastElement()).start();
        tVector.add(new EnemyBullet((this.x+this.width/2),(this.y+this.height)));
        tVector.lastElement().shift();
        new Thread(tVector.lastElement()).start();
        tVector.add(new EnemyBullet((this.x+this.width),(this.y+this.height)));
        tVector.lastElement().moveType=2;
        tVector.lastElement().shift();
        new Thread(tVector.lastElement()).start();
    }
    void delete(){
        for (int i = 0; i < tVector.size(); i++) {
            if(!tVector.elementAt(i).on_off){
                tVector.removeElementAt(i);
            }
        }
    }
    @Override
    void draw(Graphics g) {
        super.draw(g);
        drawVector(g);
        bossBloodString.drawMyself(g);
    }
    void drawVector(Graphics g){
        for (int i = 0; i < tVector.size(); i++) {
            tVector.elementAt(i).drawMyself(g);
        }
    }
    @Override
    void effect() {
        super.effect();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        gameData.xie(mrW.score);
        recordString.show();
        winString.show();
        suspendButton.suspend();
    }
}
